import { addResizeListener, removeResizeListener } from 'element-plus/lib/utils/resize-event'

export default {
    beforeMount(el, binding, vnode) {
        el.autoHeightHandle = function (el, binding, vnode) {
            let clientHeight = document.body.clientHeight
            let elOffsetTop = el.offsetTop
            let height_the_left = clientHeight - elOffsetTop
            let elH = height_the_left - binding.value
            el.style = `height:calc(${elH}px - 2rem);overflow-y:auto;`
            binding.arg = elH
        }.bind(null, el, binding)
        addResizeListener(window.document.body, el.autoHeightHandle)
        el.autoHeightHandle(el, binding, vnode)
    },
    mounted(el, binding, vnode) {
        el.autoHeightHandle(el, binding, vnode)
    },
    update(el, binding, vnode) {
        el.autoHeightHandle(el, binding, vnode)
    }, unbind: (el) => {
        removeResizeListener(el, el.autoHeightHandle)
    }
}